package com.example.zt.musicdemo02;

import android.media.MediaPlayer;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MusicActivity extends AppCompatActivity {
    private MediaPlayer mediaPlayer;
    private String mp3Path="";
    private boolean isPause = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_music);
        mediaPlayer = new MediaPlayer();
        mp3Path =  Environment.getExternalStorageDirectory().getAbsolutePath()+"/mp3/";
        Log.i("aa","........"+Environment.getExternalStorageDirectory().getAbsolutePath());
    }

    public void play(View view) throws Exception{
        if(!isPause) {
            mediaPlayer.reset();
            mediaPlayer.setDataSource(mp3Path + "land.mp3");
            mediaPlayer.prepare();
        }
        mediaPlayer.start();
        isPause = false;
    }

    public void pause(View view) {
        mediaPlayer.pause();
        isPause = true;
    }
}
